
/**
  ******************************************************************************
  * Copyright 2021 The grapilot Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       gp_udp.h
  * @author     baiyang
  * @date       2021-7-18
  ******************************************************************************
  */

#pragma once

/*----------------------------------include-----------------------------------*/
#include <WinSock2.h>
#include <Ws2tcpip.h>
/*-----------------------------------macro------------------------------------*/

/*----------------------------------typedef-----------------------------------*/

/*----------------------------------variable----------------------------------*/

/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/
class MUdpObj
{

public:
    MUdpObj();
    ~MUdpObj();

    BOOL Init(LPCTSTR lpDesIP, UINT uSrcRecvPort, UINT uDesRecvPort, LPCTSTR lpSrcIP = NULL, UINT uSrcSendPort = 0);
    int Send(char* pBuf, int nSize);
    int Recv(char* pBuf, int nSize);

    BOOL Close();
    SOCKET GetSocket();

    BOOL IsConnect() {return Connect;}
private:

    TCHAR m_SrcIP[255];
    TCHAR m_DesIP[255];
    
    UINT  m_uDesRecvPort;
    UINT  m_uSrcSendPort;
    UINT  m_uSrcRecvPort;

    SOCKET      m_sockStream;

    sockaddr_in m_SendAddr;
    sockaddr_in m_RecvAddr;

    bool Connect;
};

/*------------------------------------test------------------------------------*/


